<?php

namespace App\Http\Controllers\Chanjet;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class TplusReceiptOrder extends BaseController
{
    public function getExternalData(){
        $common = new TplusCommonController();
        $res = $common->getExternalData("TplusReceiptOrder",$this->mangerinfo['org_id']);
        return $res;
    }
    public function getlist(Request $request)
    {
        $memberinfo = $this->mangerinfo;
        $isgetall = $request->isgetall ?? 0;

        $start_time = $request->start_time;
        $end_time = $request->end_time;

        $voucherCode = $request->voucher_code;
        if($start_time && $end_time){
            $dic[] = ['VoucherDate',$start_time,$end_time];
        }
        if($voucherCode){
            $dic[] = ['Code',$voucherCode];
        }
        $dic[] = ['cpid',$memberinfo['cpid']];
        $checkData = [
            'controllerName'=>'TplusReceiptOrder',
            'org_id'=>$this->mangerinfo['org_id'],
            'condition'=>$dic
        ];
        $reportDataCheck = $this->checkReportCache($checkData);
        if($reportDataCheck['code'] != '000'){
            return response()->json(['code'=>'001','msg'=>'T+数据请求失败,请检查']);
        }

        if($reportDataCheck['data']){
            $request->cache_ids = $reportDataCheck['data'];
        }else{
            $request->cache_ids = [];
        }

        $list = \App\Models\Chanjet\TplusReceiptOrder::getList($request, $memberinfo, $isgetall);
        $totalField = $this->fieldTotal($list['list'], ['payout_amount']);
        $list['total'] = $totalField;
        return response()->json(['code' => '000', 'msg' => '操作成功', 'data' => $list]);
    }
}
